from application import db


class Group(db.Model):
    """群组"""
    __tablename__ = 'group'

    gid = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(10), nullable=False, server_default=db.FetchedValue(), info='群昵称')
    detail = db.Column(db.String(100), nullable=True, server_default=db.FetchedValue(), info='群简介')
    avatar = db.Column(db.String(200), nullable=False, server_default=db.FetchedValue())
    created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='创建时间')
    manager_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(),
                           info='管理员uid')
    status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class User(db.Model):
    """用户"""
    __tablename__ = 'user'

    uid = db.Column(db.Integer, primary_key=True)
    nickname = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue(), info='用户名')
    sex = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    salt = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
    avatar = db.Column(db.String(200), nullable=False, server_default=db.FetchedValue())
    created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='创建时间')


class Association(db.Model):
    __tablename__ = "association"

    id = db.Column(db.Integer, primary_key=True)
    group_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    user_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class Message(db.Model):
    """通知"""
    __tablename__ = "message"

    id = db.Column(db.BigInteger, primary_key=True, info='通知id')
    user_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    manager_id = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    title = db.Column(db.String(20), nullable=True, server_default=db.FetchedValue(), info='标题')
    content = db.Column(db.String(500), nullable=True, server_default=db.FetchedValue(), info='文本内容')
    created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='创建时间')
    gid = db.Column(db.BigInteger, nullable=False, server_default=db.FetchedValue(), info='群id')
    is_read = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class Information(db.Model):
    """消息"""
    __tablename__ = 'information'

    id = db.Column(db.BigInteger, primary_key=True)
    ass_id = db.Column(db.BigInteger, nullable=True, server_default=db.FetchedValue())
    user_id = db.Column(db.Integer, nullable=True, server_default=db.FetchedValue())
    member_id = db.Column(db.Integer, nullable=True, server_default=db.FetchedValue())
    manager_id = db.Column(db.Integer, nullable=True, server_default=db.FetchedValue())
    group_id = db.Column(db.BigInteger, nullable=True, server_default=db.FetchedValue())
    inform_type = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    done_type = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    is_manager = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    is_read = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
    status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())


class OauthUserBind(db.Model):
    """openid绑定uid"""
    __tablename__ = 'oauth_user_bind'

    id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    openid = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue(), info='openid')
    created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='创建时间')
